home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / resource / c / ulimit < prev   
Text File  |  1996-11-09  |  2KB  |  82 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/resource/c/RCS/ulimit,v $
  4.  * $Date: 1996/05/06 09:03:13 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: ulimit,v $
  10.  * Revision 1.2  1996/05/06 09:03:13  unixlib
  11.  * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
  12.  * Saved for 3.7a release.
  13.  *
  14.  * Revision 1.1  1996/04/19 21:29:28  simon
  15.  * Initial revision
  16.  *
  17.  ***************************************************************************/
  18.  
  19. static const char rcs_id[] = "$Id: ulimit,v 1.2 1996/05/06 09:03:13 unixlib Rel $";
  20.  
  21. #include <sys/resource.h>
  22. #include <sys/syslib.h>
  23. #include <unistd.h>
  24. #include <errno.h>
  25. #include <stdio.h>
  26.  
  27. /* Function depends on CMD:
  28.    1 = Return the limit on the size of a file, in units of 512 bytes.
  29.    2 = Set the limit on the size of a file to NEWLIMIT.  Only the
  30.    super-user can increase the limit.
  31.    3 = Return the maximum possible address of the data segment.
  32.    4 = Return the maximum number of files that the calling process
  33.    can open.
  34.    Returns -1 on errors.  */
  35. long int
  36. ulimit (int cmd, int newlimit)
  37. {
  38.   int status;
  39.  
  40.   switch (cmd)
  41.     {
  42.     case 1:
  43.       {
  44.     /* Get limit on file size.  */
  45.     struct rlimit fsize;
  46.  
  47.     status = getrlimit (RLIMIT_FSIZE, &fsize);
  48.     if (status < 0)
  49.       return -1;
  50.  
  51.     /* Convert from bytes to 512 byte units.  */
  52.     return ((long int) fsize.rlim_cur) / 512;
  53.       }
  54.     case 2:
  55.       /* Set limit on file size.  */
  56.       {
  57.     struct rlimit fsize;
  58.     fsize.rlim_cur = (int) newlimit *512;
  59.     fsize.rlim_max = (int) newlimit *512;
  60.  
  61.     return setrlimit (RLIMIT_FSIZE, &fsize);
  62.       }
  63.     case 3:
  64.       /* Get maximum address for `brk'.  This lies between
  65.          __lomem and __lomem + current limit on address size.  */
  66.       {
  67.     struct rlimit dsize;
  68.     status = getrlimit (RLIMIT_DATA, &dsize);
  69.     if (status < 0)
  70.       return -1;
  71.  
  72.     return ((long int) &__lomem) + dsize.rlim_cur;
  73.       }
  74.     case 4:
  75.       return FOPEN_MAX;
  76.  
  77.     default:
  78.       errno = EINVAL;
  79.       return -1;
  80.     }
  81. }
  82.